<template>
  <view class="main-container">
    <!-- 个人信息 -->
    <view class="info-list">
      <view class="info-item" @tap.stop.prevent="toUserInfoEdit">
        <text class="info-item-left">头像</text>
        <view class="info-item-right">
          <image class="user-logo" :src="userInfo.user_logo"></image>
        </view>
      </view>
      <view class="info-item" @tap.stop.prevent="toUserInfoEdit">
        <text class="info-item-left">昵称</text>
        <view class="info-item-right">
          <text class="info-content">{{ userInfo.user_name }}</text>
          <image class="icon-arrow" src="/static/image/arrow_right.png"></image>
        </view>
      </view>
      <view class="info-item" @tap.stop.prevent="toUserInfoEdit">
        <text class="info-item-left">性别</text>
        <view class="info-item-right">
          <text class="info-content">{{ userInfo.user_gender == 1 ? '男' : '女' }}</text>
          <image class="icon-arrow" src="/static/image/arrow_right.png"></image>
        </view>
      </view>
      <view class="info-item" @tap.stop.prevent="toUserInfoEdit">
        <text class="info-item-left">姓名</text>
        <view class="info-item-right">
          <text class="info-content">{{ userInfo.real_name || '' }}</text>
          <image class="icon-arrow" src="/static/image/arrow_right.png"></image>
        </view>
      </view>
      <view class="info-item" @tap.stop.prevent="toUserInfoEdit">
        <text class="info-item-left">生日</text>
        <view class="info-item-right">
          <text class="info-content">{{ userInfo.user_birthday || '' }}</text>
          <image class="icon-arrow" src="/static/image/arrow_right.png"></image>
        </view>
      </view>
     <!-- <view class="info-item" @tap.stop.prevent="toUserInfoEdit">
        <text class="info-item-left">身份证号</text>
        <view class="info-item-right">
          <text class="info-content">{{ cardIdHidden(userInfo.card_id) }}</text>
          <image class="icon-arrow" src="/static/image/arrow_right.png"></image>
        </view>
      </view> -->
      <!-- <view class="info-item" @tap.stop.prevent="toPhoneEdit">
        <text class="info-item-left">手机号</text>
        <view class="info-item-right">
          <text class="info-content">{{ phoneHidden(userInfo.user_phone) }}</text>
          <image class="icon-arrow" src="/static/image/arrow_right.png"></image>
        </view>
      </view> -->
      <view class="info-item" @tap.stop.prevent="toUserInfoEdit">
        <text class="info-item-left">职业</text>
        <view class="info-item-right">
          <text class="info-content">{{ userInfo.user_mbrVocation || '' }}</text>
          <image class="icon-arrow" src="/static/image/arrow_right.png"></image>
        </view>
      </view>
      <view class="info-item" @tap.stop.prevent="toUserInfoEdit">
        <text class="info-item-left">联系地址</text>
        <view class="info-item-right">
          <text class="info-content">{{ userInfo.user_address || '' }}</text>
          <image class="icon-arrow" src="/static/image/arrow_right.png"></image>
        </view>
      </view>
			<view class="info-item" @tap.stop.prevent="toAuthNew" v-if="approve == '1'&& isDisplay">
			  <text class="info-item-left">更改认证</text>
			  <view class="info-item-right">
			    <image class="icon-arrow" src="/static/image/arrow_right.png"></image>
			  </view>
			</view>
			<view class="info-item" @tap.stop.prevent="toExit">
			  <text class="info-item-left">退出登录</text>
			  <view class="info-item-right">
			    <image class="icon-arrow" src="/static/image/arrow_right.png"></image>
			  </view>
			</view>
    </view>
    <view class="info-save" @tap="personalInfoSave" v-if="infoSaveBtn">保存</view>

    <!-- 奖励领取 -->
    <block v-if="!isReceive && memberInfoAddShow">
      <view class="reward-container" v-if="showReward">
        <view class="reward-title">完善个人信息可领取奖励</view>
        <view class="reward-list">
          <view class="reward-item" v-if="memberInfoAdd && memberInfoAdd.point">
            <view class="reward-item-title">领取积分</view>
            <view class="reward-item-info">
              <text class="reward-item-num">x{{ memberInfoAdd.point }}</text>
              <text class="reward-item-txt">完善信息可获得积分</text>
              <view class="reward-item-image">
                <image src="/static/image/my/reward-bg2.png" mode="widthFix"></image>
              </view>
            </view>
          </view>
          <!-- 优惠券 -->
          <block v-if="giftpackGoodsList" v-for="(item, index) in giftpackCouponList" :key="index">
            <view class="reward-item">
              <view class="reward-item-title">领取优惠券</view>
              <view class="reward-item-info">
                <text class="reward-item-num">x{{ item.couponNo }}</text>
                <text class="reward-item-txt">{{ item.couponName }}</text>
                <view class="reward-item-image">
                  <image src="/static/image/my/reward-bg2.png" mode="widthFix"></image>
                </view>
              </view>
            </view>
          </block>
          <!-- 商品兑换券 -->
          <block v-if="giftpackGoodsList" v-for="(item, index) in giftpackGoodsList" :key="index">
            <view class="reward-item">
              <view class="reward-item-title">{{ item.couponName }}</view>
              <view class="reward-item-info">
                <text class="reward-item-num">x1</text>
                <text class="reward-item-txt">{{ item.goodsName }}</text>
                <view class="reward-item-image">
                  <image src="/static/image/my/reward-bg2.png" mode="widthFix"></image>
                </view>
              </view>
            </view>
          </block>
        </view>
        <view class="reward-submit"
          :style="'background-color:' + (memberInfoAddBtnShow ? '#FF5642' : 'rgba(255, 86, 66, 0.5)')" @tap="getReward">
          立即领取</view>
      </view>
    </block>
		
		<u-popup :show="showAuth" @close="onClose" mode="center" custom-style="width:90%;border-radius:24rpx">
		  <view class="auth-box2" @tap.stop.prevent="doNoting">
		    <view class="dialog-title">身份认证</view>
				<view class="dialog-authbox">
					<text style="width: 200rpx;">证件类型：</text>
					<!-- <radio-group @change="changeAuthType">
					  <label class="info-content">
					    <radio style="margin-right: 30rpx" value="01" color="#ff4444"
							:checked="authType == '01'" :disabled="authType == '00'">身份证</radio>
					    <radio value="00" :checked="authType == '00'" color="#ff4444" :disabled="authType == '01'">户口簿</radio>
					  </label>
					</radio-group> -->
          <!-- <picker style="width: 100%;" @change="bindPickerChange" :value="certificateTypeIndex" :range="certificateTypeArray">
            <view class="picker-item">
              <view class="uni-input" style="display: inline-block;">{{certificateTypeArray[certificateTypeIndex]}}</view>
              <image class="picker-arrow" src="/static/image/arrow_right.png"></image>
            </view>
          </picker> -->
          <view class="ipt-username" :value="authParams.certNo">{{pickerValue}}</view>
				</view>
				<view class="iptbox-new">
					<view class="dialog-iptbox" style="flex: 1;">
					  <view class="dialog-img">
					    <image :src="staticBaseUrl + '/static/image/my/card-1.png'" mode="widthFix"></image>
					  </view>
					  <input type="text" class="ipt-username" :value="authParams.certNo" placeholder="请输入证件号码" maxlength="18"
		        @input="bindCardIdChange" :disabled="approve == '1'"/>
					</view>
					<view class="btn-confirm idCard-btn" @tap.stop.prevent="idCardSearch">查 询</view>
				</view>
				<view class="dialog-iptbox" v-if="authFlag && cardList.length && cardSelectFlag" @tap.stop.prevent="bankCardSelect">
					<view class="dialog-img">
					  <image :src="staticBaseUrl + '/static/image/my/card-3.png'" mode="widthFix"></image>
					</view>
					<input type="text" class="ipt-username" :value="cardHidden(authParams.cardNo)" placeholder="请选择银行卡号" disabled/>
					<image class="select-btn" :src="'/static/image/merchant/' + (showAuthSelect ? 'arrow_down.png' : 'arrow_up.png')"></image>
					<view class="option-view" v-if="showAuthSelect">
						<view v-for="(item, index) in cardList" @tap.stop.prevent="selectBankCard(item)"
						class="bank-item" :key="index">{{item.card}}</view>
					</view>
				</view>
				<view class="dialog-iptbox" v-if="authFlag">
				  <view class="dialog-img">
				    <image :src="staticBaseUrl + '/static/image/my/head.png'" mode="widthFix"></image>
				  </view>
				  <input type="number" class="ipt-username" :value="phoneHidden(authParams.phone)" placeholder="手机号码" 
							style="flex: 1"	@input="bindPhoneChange" disabled/>
					<view class="authCode" :style="'color:' + (codeDisabled ? '#FAB7B4' : '#F35C56')" 
					@tap.stop.prevent="getMsgCode">{{messageText}}</view>
				
				</view>
				<view class="dialog-iptbox" v-if="authFlag">
					<view class="dialog-img">
					  <image :src="staticBaseUrl + '/static/image/my/head.png'" mode="widthFix"></image>
					</view>
					<input type="number" class="ipt-username" :value="authParams.authCode" placeholder="验证码" @input="bindAuthCodeChange" />
				</view>
				<view class="errorBox" v-if="showError">
					<view class="error-img">
						<image :src="staticBaseUrl + '/static/image/my/error.png'" mode="widthFix"></image>
					</view>
					<view class="error-info">{{ errInfo }}</view>
				</view>
				<view class="dialog-btnbox" v-if="authFlag">
					<view class="btn-cancel" @tap.stop.prevent="onClose">取消</view>
					<view class="btn-confirm" @tap.stop.prevent="authConfirm2" 
					:style="'color:' + (authDisabled ? '#FAB7B4;opacity: 0.6' : '#fff;opacity: 1')">确定</view>
				</view>
			</view>
		</u-popup>
  </view>
</template>
<script module="util" lang="wxs" src="../../../utils/util.wxs"></script>
<script>
  const app = getApp();
	import {
		staticBaseUrl
	} from '@/utils/constant.js'

  const utils = require('../../../utils/util.js');
  import {
    http
  } from '@/utils/commonRequest.js'; // 局部引入
  export default {
    data() {
      return {
        isDisplay: true,
        pickerValue:'',
        certificateTypeIndex:1,
        certificateTypeArray:['户口簿','身份证','护照','临时身份证','港澳通行证','台湾通行证'],
				staticBaseUrl,
        genderIndex: 0,

        genderArray: [{
            id: 0,
            name: '女'
          },
          {
            id: 1,
            name: '男'
          }
        ],

        birthday: '1990-01-01',
        editUserInfo: {
          userLogo: '',
          userName: '',
          realName: '',
          cardId: '',
          userPhone: '',
          userGender: '',
          userBirthday: '',
          userMbrvocation: '',
          address: ''
        },

        userInfo: {
          user_logo: '',
          user_name: '',
          user_gender: 0,
          real_name: '',
          user_birthday: '',
          user_mbrVocation: '',
          user_address: ''
        },

        giftpackCouponList: '',
        giftpackGoodsList: '',
        showReward: true,
        infoSaveBtn: false,
        isReceive: true,
        disabled: true,
        currentDate: '',

        memberInfoAdd: {
          point: ''
        },

        memberInfoAddBtnShow: '',
        memberInfoAddShow: '',
				// 认证框 new=======
				showAuth: false,
				authFlag: null,
				showAuthSelect: false,
				cardList: null,
				messageText: '获取验证码',
				codeDisabled: false,
				authDisabled: true,
				showError: false,
				errInfo: '',
				approve: null,
				memberInfo: null,
				/** 去认证上传参数 */
				authParams: {
				  certNo: '',
					certTp: '1',
				  cardNo: '',
					phone: '',
					idno_encrypt:'',
					phone_encrypt:''
				},
				toAuthLoading: false   ,// 认证提交loading
				authType: '',
        cardSelectFlag: true,
      };
    }
    /**
     * 生命周期函数--监听页面加载
     */
    ,
    onLoad: function(options) {
      this.onLoadClone3389(options);
			this.authType = uni.getStorageSync('authFlag')
      // 更改认证
      let bankTypeFlag = uni.getStorageSync('bankType')
      console.log('bankTypeFlag', bankTypeFlag);
      if(bankTypeFlag == '00'){
        this.isDisplay = false;
      }
      else{
        this.isDisplay = true;
      }
    },
    onShow: function() {
      let flag = uni.getStorageSync('ZSNSH_USER_INFO_MODIFY');
			// #ifdef H5
			this.memberInfo = uni.getStorageSync('memberInfo')
			// #endif
			// #ifdef MP-WEIXIN
			this.memberInfo = app.globalData.memberInfo
			// #endif
      if (flag) {
        this.onLoadClone3389({});
      }
    },
    methods: {
			
			doNoting() {
			  console.log('占位：函数 doNoting 未声明');
			},
			
			// 认证类型
			// changeAuthType: function(e){
			// 	// 修改认证不可修改认证类型
			// 	// let value = e.detail.value;
			// 	// this.authType = value;
			// },
      bindPickerChange: function(e) {
        let certificateMap = [
          {index: "00", value: "户口簿"},
          {index: "01", value: "身份证"},
          {index: "02", value: "护照"},
          {index: "03", value: "军官证"},
          {index: "04", value: "士兵证"},
          {index: "05", value: "港澳通行证"},
          {index: "06", value: "台湾通行证"},
          {index: "07", value: "临时身份证"},
          {index: "08", value: "外国人居留证"},
          {index: "09", value: "警官证"},
          {index: "10", value: "无身份证"},
          {index: "11", value: "其他证件"},
          {index: "12", value: "组织机构代码"},
          {index: "13", value: "营业执照号"},
          {index: "14", value: "批文"},
          {index: "15", value: "主管证明"},
          {index: "16", value: "组织代码证"},
          {index: "17", value: "电子现金证件"},
          {index: "18", value: "港澳居住证"},
          {index: "19", value: "台湾居住证"}
        ]
        console.log('picker发送选择改变，携带值为', e.detail.value)
        // this.index = e.detail.value
        this.certificateTypeIndex = e.detail.value
        let value = e.detail.value;
        let a = certificateMap.find(item => {
          return item.value == this.certificateTypeArray[value];
        })
				this.authType = a.index;
        console.log("authType", this.authType);
				this.authParams.authCode = '';
				this.authParams.phone = '';
				this.authParams.cardNo = '';
				this.authDisabled = true;
				this.cardList = [];
				this.authFlag = false;
      },
			
			// 银行卡号脱敏
			cardHidden(no) {
				return no.replace(/^(.{4})(?:\d+)(.{4})$/, "$1 **** **** $2")
			},
			
      cardIdHidden(cardId) { //身份证号脱敏
        if (null == cardId || undefined == cardId || 'undefined' == cardId || 0 == cardId.length) {
          return '';
        }
        cardId = cardId + '';
        return cardId.substring(0, 7) + '******' + cardId.substring(13);
      },
      phoneHidden(phone) { //手机号脱敏
        if (null == phone || undefined == phone || 'undefined' == phone || 0 == phone.length) {
          return '';
        }
        phone = phone + '';
        return phone.substring(0, 3) + '****' + phone.substring(7);
      },
      /**
       * 生命周期函数--监听页面加载
       */
      onLoadClone3389: function(options) {
        var date = new Date();
        var currentDate = utils.formatDate(date);
        this.currentDate = currentDate
				let currentUrl = utils.getCurrentPageUrlWithArgs();
				this.$checkAuth('redirect', currentUrl).then(res => {
				// this.$checkAuth().then((res) => {
						this.getPersonalInfo();
						this.getRewardInfo();
					})
        
      },


      /** 获取个人信息 */
      getPersonalInfo: function() {
				uni.showLoading({
					title: '加载中'
				});
        http.get('/personal/userInfo', {
            params: {
              type: 'seconds'
            }
          })
          .then((res) => {
            console.log(res);
            let birthday = res.data.userinfo.user_birthday;
            res.data.userinfo.user_birthday = birthday;
            let userInfo = res.data.userinfo;
						this.userInfo = userInfo
						this.approve = userInfo.approve == '1' ? '1' : '0'
            this.editUserInfo = {
              userLogo: userInfo.user_logo,
              userName: userInfo.user_name,
              realName: userInfo.real_name,
              cardId: userInfo.card_id,
              userPhone: userInfo.user_phone_encrypt,
              userGender: userInfo.user_gender,
              userBirthday: userInfo.user_birthday,
              userMbrvocation: userInfo.user_mbrVocation,
              address: userInfo.user_address
            };
            let a = this.editUserInfo.cardId;
						if(a){
							a = a.slice(6, 14);
							a = a.slice(0, 4) + '-' + a.slice(4, 6) + '-' + a.slice(6);
							this.birthday = a
						}
						uni.setStorageSync('authFlag',userInfo.idType)
						this.authType = userInfo.idType;
            // this.authType = '18'
            let certificateMap = [
              {index: "00", value: "户口簿"},
              {index: "01", value: "身份证"},
              {index: "02", value: "护照"},
              {index: "03", value: "军官证"},
              {index: "04", value: "士兵证"},
              {index: "05", value: "港澳通行证"},
              {index: "06", value: "台湾通行证"},
              {index: "07", value: "临时身份证"},
              {index: "08", value: "外国人居留证"},
              {index: "09", value: "警官证"},
              {index: "10", value: "无身份证"},
              {index: "11", value: "其他证件"},
              {index: "12", value: "组织机构代码"},
              {index: "13", value: "营业执照号"},
              {index: "14", value: "批文"},
              {index: "15", value: "主管证明"},
              {index: "16", value: "组织代码证"},
              {index: "17", value: "电子现金证件"},
              {index: "18", value: "港澳居住证"},
              {index: "19", value: "台湾居住证"}
            ]
            let valueName = certificateMap.find(item => {
              return item.index == this.authType;
            }).value;
            this.pickerValue = valueName;
						uni.hideLoading()
          });
      },

      /** 获取领取奖励信息 */
      getRewardInfo: function() {
        http.get('/memberInfoAdd/queryMemberInfoAdd').then((res) => {
          //当没有配置奖励时不显示完善有礼的内容
          let memberInfoAddShow = false;
          let memberInfoAdd = res.data.memberInfoAdd;

          if (undefined != memberInfoAdd) {
            memberInfoAddShow = true;
          }

          this.memberInfoAdd = res.data.memberInfoAdd
          this.giftpackCouponList = res.data.giftpackCouponList
          this.giftpackGoodsList = res.data.giftpackGoodsList
          this.isReceive = res.data.hasReceiveGift
          this.memberInfoAddBtnShow = res.data.memberInfoAddBtnShow
          this.memberInfoAddShow = memberInfoAddShow
        });
      },

      /** 立即领取 */
      getReward: function() {
        if (!this.memberInfoAddBtnShow) {
          return;
        }

        http.get('/memberInfoAdd/receiveGift').then((res) => {
          console.log(res);

          if (res.data.code == '200') {
            uni.showToast({
              title: 'res.data.msg',
              icon: 'success'
            });
            this.isReceive = true
          }
          
          if (res.data.code == '500' && res.data.msg == '信息未完善,请核对信息') {
            uni.showToast({
              icon: 'none',
              title: res.data.msg
            });
              this.showReward = false
              this.infoSaveBtn = true
              this.disabled = false
          }

          if (res.data.code == '500' && res.data.msg == '商户礼包已被抢完') {
            uni.showToast({
              icon: 'none',
              title: res.data.msg
            });
            this.isReceive = true
          }

          if (res.data.code !== '200') {
            uni.showToast({
              title: res.data.msg,
              icon: 'none'
            });
          }
        });
      },

      /** 修改个人信息获取 */
      bindNameChange: function(e) {
        this.editUserInfo.userName = e.detail.value;
      },

    

      /** 个人信息保存 */
      personalInfoSave: function() {
        let nameReg = /^[\u4E00-\u9FA5A-Za-z]+$/; //名字正则

        let phoneReg = /^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9]))\d{8}$/; //手机号正则

        let cardIdReg = /^\d{15}|\d{}18$/; //身份证号正则

        if (this.editUserInfo.userName == '') {
          uni.showToast({
            icon: 'error',
            title: '昵称不能为空'
          });
          return;
        }

        if (!nameReg.test(this.editUserInfo.realName)) {
          uni.showToast({
            icon: 'error',
            title: '姓名格式错误'
          });
          this.editUserInfo.realName = '';
          return;
        }

        // if (!cardIdReg.test(this.editUserInfo.cardId)) {
        //   uni.showToast({
        //     icon: 'none',
        //     title: '身份证号格式错误，请重新输入'
        //   });
        //   return;
        // }

        let birthdayStr = this.editUserInfo.cardId;
        birthdayStr = birthdayStr.slice(6, 14);
        birthdayStr = birthdayStr.slice(0, 4) + '-' + birthdayStr.slice(4, 6) + '-' + birthdayStr.slice(6);

        if (birthdayStr !== this.editUserInfo.userBirthday) {
          uni.showToast({
            title: '身份证号与生日日期不匹配，请确认后重新输入',
            icon: 'none'
          });
          return;
        }

        if (!phoneReg.test(this.editUserInfo.userPhone)) {
          uni.showToast({
            icon: 'none',
            title: '手机号格式错误，请重新输入'
          });
          return;
        }

        if (this.editUserInfo.userMbrvocation == '') {
          uni.showToast({
            icon: 'error',
            title: '职业不能为空'
          });
          return;
        }

        if (this.editUserInfo.address == '') {
          uni.showToast({
            title: '地址不能为空',
            icon: 'error'
          });
          return;
        }

        this.editUserInfo.userBirthday = this.birthday;
        http.post('/member/saveUser', {
          params: this.editUserInfo
        }).then((res) => {
          if (res.data.code == '200') {
            console.log(res);
            uni.showToast({
              icon: 'success',
              title: '信息修改成功'
            });
            this.showReward = true
            this.infoSaveBtn = false
            this.disabled = true
          }
        });
      },

      toUserInfoEdit: function() {
        uni.navigateTo({
          url: '/pages/personalInfo/userInfoEdit/userInfoEdit'
        });
      },

      toPhoneEdit: function() {
        uni.navigateTo({
          url: '/pages/personalInfo/phoneEdit/phoneEdit'
        });
      },
			
			
			
			// 认证new
			authConfirm2: function() {
				let that = this;
				let cardIdReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; //身份证号正则
				let url = 'mtBankInfo/userAuthByIdno';
				if(this.toAuthLoading) { return }
				if(this.approve == '1'){ url = 'mtBankInfo/updateAuthByIdno' }
				
				if(!(this.authParams.phone && this.authParams.authCode)){
					return
				}
				// if (!cardIdReg.test(this.authParams.certNo)) {
				//   uni.showToast({
				//     icon: 'none',
				//     title: '身份证号格式错误，请重新输入'
				//   });
				//   return;
				// }
				if(utils.isEmpty(this.authParams.authCode)){
					uni.showToast({
					  icon: 'none',
					  title: '请输入正确短信验证码'
					});
					return;
				}
				let params = {
					memberId: this.memberInfo.id,
					idno: this.userInfo.idno_encrypt,
					phone: this.authParams.phoneEnc,
					code: this.authParams.authCode,
					authFlag: this.authType,
					bankType: uni.getStorageSync('bankType'),
          cardNo: this.authParams.cardEnc
				}
				// if(this.authParams.cardEnc){
				// 	params.cardNo = this.authParams.cardEnc
				// }
				uni.showLoading({
					title: '提交中'
				})
				this.toAuthLoading = true
				http.get(url, {params: params})
				.then((res) => {
					res = res.data;
					if(res.code == '200'){
						uni.showToast({
							title: that.approve == '1' ? '修改成功' : '认证成功',
							icon: 'success'
						});
						let data = this.userInfo;
						data.approve = '1';
						that.onClose()
						that.userInfo = data
						that.approve = '1'
						that.getDetailMemberInfo()
					}else {
						that.showError = true
						that.errInfo = res.msg
						console.log('????????',that.errInfo,res.msg)
					}
					uni.hideLoading()
					that.toAuthLoading = false
				}).catch((err) => {
					uni.hideLoading()
					that.toAuthLoading = false
					console.log(err);
				});
			},
			
			// 银行卡号选择框
			bankCardSelect: function(){
				this.showAuthSelect = !this.showAuthSelect
			},
			
			// 选择银行卡号
			selectBankCard: function(item){
				this.authParams.cardNo = item.card;
				this.authParams.cardEnc = item.cardEnc;
				let that = this;
				http.get('/mtBankInfo/getPhoneByCard', {
					params: { 
						cardNo: item.cardEnc,
						authFlag: that.authType,
						bankType: uni.getStorageSync('bankType')
					},
				})
					.then((res) => {
						res = res.data;
						if(res.code == '200'){
							console.log('选择银行卡号获取手机号===',res)
							that.authParams.phone = res.phone;
							that.authParams.phoneEnc = res.phoneEnc;
						}else{
							uni.showToast({
								icon: 'none',
								title: res.msg
							});
						}
					})
				if(this.showAuthSelect){ this.bankCardSelect() }
			},
			
			// 获取短信验证码
			getMsgCode: function(){
				if(this.codeDisabled){
					return;
				}
				
				let that = this;
				let phone = that.authParams.phoneEnc;
				// if (utils.isEmpty(phone) || !utils.verifyPhone(phone)) {
				// 	utils.message('请输入正确的手机号！');
				// 	return;
				// }
				
				this.codeDisabled = true;
				
				let params = { phone: phone }
				uni.showLoading({
					title: '发送中'
				});
				http.get('/mtBankInfo/sendCodeMt', {params: params})
					.then((res) => {
						res = res.data;
						uni.hideLoading();
						if ('200' == res.code) {
							utils.message('验证码已发送');
							let second = 60;
							let a = setInterval(function() {
								second--;
								if (second == 0) {
									that.messageText = '获取验证码'
									that.codeDisabled = false
									clearInterval(a);
								} else {
									that.messageText = second + 'S后获取'
								}
							}, 1000);
						}else {
							utils.message(res.msg);
							that.codeDisabled = false
						}
					}).catch((err) => {
						uni.hideLoading();
						that.codeDisabled = false
						utils.message('获取验证码失败')
						console.log('验证码err',err)
				})
			},
			
			toAuthNew: function() {
				if(this.approve == '1' && this.userInfo.idno){
					this.authParams.certNo = this.userInfo.idno
				}
				this.showAuth = true
			},
			
			toExit: function(){
				uni.showModal({
					title: '提示',
				  content: '确定要退出登录吗？',
				  showCancel: true,
				  confirmColor: "#FF4A4A",
				  cancelColor: "#B3B1B1",
				  success: function(res) {
						if (res.confirm) {
							http.get('/miniapp/mtLogout', {})
							  .then(async(res) => {
									res = res.data
									if(res.code == '200'){
										// await uni.setStorageSync('LOGIN_LOGIN', 'expire');
										await uni.setStorageSync('LOGIN_LOGIN', 'expire2');
										wx.removeStorageSync('LOGIN_JSESSIONID_HELPER')
										await uni.switchTab({
										  url: '/pages/my/my'
										});
									}else{
										utils.tips(res.msg)
									}
								}).catch(err => {
									console.log('登出功能err信息==',err)
								})
						}
						uni.removeStorageSync('outlink')
					}
				})
			},
			
			onClose: function() {
				this.showAuth = false
			  this.showScan = false
				this.showError = false
				this.authFlag = false
				this.errInfo = ''
				this.authParams = {
			    custName: '',
			    certTp: '1',
			    cardNo: '',
					phone: '',
					certNo: ''
			  }
			},
			
			// 身份证查询
			idCardSearch: function(){
				let that = this;
				let cardIdReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; //身份证号正则
				let url = '/mtBankInfo/getPhoneByIdno';
				if(this.approve == '1'){
					url = '/mtBankInfo/getPhoneByIdnoUpdate'
				}
				// if (!cardIdReg.test(this.authParams.certNo)) {
				//   uni.showToast({
				//     icon: 'none',
				//     title: '身份证号格式错误，请重新输入'
				//   });
				//   return;
				// }
				console.log(this.userInfo,'8798798790890')
				let params = {
					idno: this.userInfo.idno_encrypt,
					memberId: this.memberInfo.id,
					authFlag: this.authType
				}
				that.showError = false;
				uni.showLoading({
					title: '查询中'
				});
				http.get(url, {params: params})
					.then((res) => {
						uni.hideLoading()
						res = res.data;
						if(res.code == '200'){
							console.log('身份证查询',res);
							if(res.bankType){
								uni.setStorageSync('bankType',res.bankType)
							}
							// 情况1：总行
              if(res.phone && res.phoneEnc){
                console.log("总行");
                that.cardSelectFlag = false;
                that.authParams.phone = res.phone;
                that.authParams.phoneEnc = res.phoneEnc;
                that.authParams.cardEnc = res.card;
                that.authFlag = true
                uni.getStorageSync('isDisplay')
                if(res.phone == ''){
                  uni.showToast({
                    icon: 'none',
                    title: '未查询到您在我行的预留手机号，请至柜面录入后进行认证'
                  });
                }
              }
              // 情况2：村行
              else if(res.cardList){
                console.log("村行");
                that.cardSelectFlag = true;
                if(res.cardList && res.cardList.length > 0){
                  that.cardList = res.cardList
                  that.authParams.cardNo = res.cardList[0]
                  that.selectBankCard(res.cardList[0])
                  that.authFlag = true
                }else{
                  uni.showToast({
                    icon: 'none',
                    title: '很抱歉，未查询到您的银行卡信息，暂不支持注册'
                  });
                  that.authFlag = false;
                  that.cardList = null;
                  that.authParams.cardNo = null;
                  that.authParams.phone = ''
                }
              }
						}else{
							uni.showToast({
								icon: 'none',
								title: res.msg
							});
						}
						that.authParams.authCode = ''
						that.authDisabled = true
					}).catch((err) => {
						uni.hideLoading()
			      console.log(err);
			    })
				
			},
			
			bindCardIdChange: function(e) {
			  this.authParams.certNo = e.detail.value; // if (this.authParams.certNo !== this.data.userInfo.card_id) {
			},
			
			bindAuthCodeChange:function(e) {
				this.authParams.authCode = e.detail.value;
				this.authDisabled = !(this.authParams.phone && this.authParams.authCode)
			},
			
			bindPhoneChange: function(e) {
				this.authParams.phone = e.detail.value;
				this.authDisabled = !(this.authParams.phone && this.authParams.authCode)
			},
			
			bindCardChange: function(e) {
			  this.authParams.cardNo = e.detail.value;
			},
    
		}
  };
</script>
<style>
  .main-container {
    padding: 24rpx;
  }

  .info-list {
    padding: 0 8rpx;
    background: #ffffff;
    box-shadow: 0px 20rpx 60rpx 0px rgba(112, 136, 210, 0.1);
    border-radius: 16rpx;
  }

  .info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 28rpx;
    min-height: 92rpx;
    border-bottom: 1px solid #eaeaea;
  }

  .info-item:last-child {
    border-bottom: none;
  }

  .info-item-left {
    color: #999;
    font-size: 32rpx;
  }

  .info-item-right {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    width: 430rpx;
    line-height: 40rpx;
    font-size: 28rpx;
    color: #333;
  }

  .user-logo {
    width: 100rpx;
    height: 100rpx;
    border-radius: 50%;
    background-color: #eee;
  }

  .info-content {
    flex: 1;
    text-align: right;
  }

  .icon-arrow {
    margin-left: 16rpx;
    flex-shrink: 0;
    width: 24rpx;
    height: 24rpx;
  }

  .reward-container {
    margin-top: 40rpx;
  }

  .reward-title {
    margin-bottom: 20rpx;
    font-weight: bold;
  }

  .reward-list {
    background-color: #fff;
    border-radius: 24rpx;
    display: flex;
    flex-wrap: nowrap;
    overflow-x: scroll;
    width: 100%;
    padding: 40rpx 30rpx;
    box-sizing: border-box;
  }

  .reward-item {
    border-radius: 24rpx;
    border: 1px solid rgba(22, 158, 255, 0.1);
    width: 270rpx;
    flex-shrink: 0;
    overflow: hidden;
    padding: 20rpx;
    box-sizing: border-box;
    margin-right: 20rpx;
    position: relative;
  }

  .reward-item:nth-child(1) {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.1), rgba(22, 158, 255, 0.1));
  }

  .reward-item:nth-child(2) {
    background: linear-gradient(90deg, rgba(239, 191, 213, 0.1), rgba(157, 97, 253, 0.1));
  }

  .reward-item:nth-child(3) {
    background: linear-gradient(90deg, rgba(188, 227, 128, 0.1), rgba(55, 197, 87, 0.1));
  }

  .reward-item-title {
    font-weight: bold;
    margin-bottom: 20rpx;
    color: rgb(43, 23, 15);
  }

  .reward-item-txt {
    font-size: 24rpx;
    color: rgb(153, 153, 153);
    display: block;
    width: 180rpx !important;
    overflow-wrap: break-word;
    overflow: hidden;
  }

  .reward-item-num {
    position: absolute;
    bottom: 20rpx;
    right: 20rpx;
    font-size: 28rpx;
    color: rgb(255, 86, 66);
  }

  .reward-item-image {
    width: 80rpx;
    position: absolute;
    bottom: 0;
    right: 10rpx;
  }

  .reward-item-image image {
    width: 100%;
  }

  .reward-submit,
  .info-save {
    line-height: 84rpx;
    text-align: center;
    color: white;
    background-color: red;
    border-radius: 40rpx;
    margin: 44rpx 0;
    font-weight: bold;
    letter-spacing: 2rpx;
  }
	
	.auth-box2 {
	  padding: 50rpx 34rpx;
	  box-sizing: border-box;
	}
	
	.dialog-title {
	  text-align: center;
	  color: #000;
	  font-size: 36rpx;
	  font-weight: bold;
	  margin-bottom: 30rpx;
	}
	
	.iptbox-new{
		display: flex;
		align-items: center;
	}
	
	.dialog-iptbox {
	  display: flex;
	  position: relative;
	  padding-left: 16rpx;
	  font-size: 28rpx;
	  height: 96rpx;
	  background-color: #eee;
	  border-radius: 24rpx;
	  align-items: center;
	  margin-bottom: 16rpx;
	}
	
	.dialog-authbox{
		display: flex;
		align-items: center;
		padding-left: 16rpx;
		font-size: 28rpx;
		height: 96rpx;
	}
	
	.dialog-img {
	  width: 48rpx;
	  height: 48rpx;
	  margin-right: 24rpx;
	}
	
	.dialog-img image {
	  width: 100%;
	}
	
	.ipt-username{
	  width: 80%;
		padding-top: 6rpx;
	}
	
	.btn-confirm {
	  width: 260rpx;
	  height: 84rpx;
	  background-color: #fff;
	  color: #666;
	  font-size: 34rpx;
	  line-height: 84rpx;
	  border: 1rpx solid #eaeaea;
	  border-radius: 42rpx;
	  text-align: center;
	}
	
	
	.idCard-btn{
		width: auto !important;
		min-width: 160rpx;
		padding: 0 10rpx;
		margin-left: 10rpx;
	}
	
	.select-btn {
	  width: 24rpx;
	  height: 24rpx;
	}
	
	.option-view{
		position: absolute;
		left: 0;
		top: 94rpx;
		width: 100%;
		max-height: 200rpx;
		background-color: #fff;
		border: 2rpx solid #eee;
		border-radius: 24rpx;
		overflow-y: scroll;
		padding: 20rpx 0 20rpx 54rpx;
		z-index: 9;
	}
	
	.bank-item{
		font-size: 28rpx;
		padding: 12rpx 0;
	}
	
	.authCode{
		font-size: 32rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		word-break: keep-all;
		padding-right: 10rpx;
	}
	
	.errorBox {
	  margin-top: 40rpx;
	  display: flex;
	}
	
	.error-img {
	  width: 32rpx;
	  height: 32rpx;
	  margin-right: 14rpx;
	}
	
	.error-img image {
	  width: 100%;
	}
	
	.error-info {
	  color: #666;
	  font-size: 26rpx;
	  font-weight: bold;
	}
	
	.dialog-btnbox {
	  padding: 40rpx 0rpx;
	  display: flex;
	  justify-content: space-between;
	}
	
	.btn-cancel,
	.btn-confirm {
	  width: 260rpx;
	  height: 84rpx;
	  background-color: #fff;
	  color: #666;
	  font-size: 34rpx;
	  line-height: 84rpx;
	  border: 1rpx solid #eaeaea;
	  border-radius: 42rpx;
	  text-align: center;
	}
	
	.btn-confirm {
	  background: linear-gradient(140deg, #ffc996 0%, #ed176e 100%);
	  color: white;
	}

  .picker-item{
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .picker-arrow {
    width: 24rpx;
    height: 24rpx;
    transform: rotate(90deg);
  }
</style>
